﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mvc4Learn.Controllers;
using Mvc4Learn.Models;

namespace GqqMvcWeb.Tests.Controllers
{
    [TestClass]
    public class HomeControllerTest
    {
        [TestMethod]
        public void Index()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
            // Assert
            Assert.AreEqual("修改此模板以快速启动你的 ASP.NET MVC 应用程序。", result.ViewBag.Message);
        }

        [TestMethod]
        public void About()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.About() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }

        [TestMethod]
        public void Test()
        {
            HomeController controller = new HomeController();

            TestModels t = new TestModels { IsTrue = true, Money = 3, Name = "gqq" };

            var result = controller.Test(t);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
            var message = controller.ModelState["Money"].Errors[0].ErrorMessage;
            var states = controller.ModelState;
            Assert.AreEqual("Invalid", message);
            var viewModel = (ViewResult)result;
            //            viewModel.
        }

        [TestMethod]
        public void TestHtmlDecode()
        {
            HomeController controller = new HomeController();
            //            HtmlHelper
            var s1 = System.Web.HttpUtility.UrlDecode("http%3A%2F%2Fblog.sina.com.cn%2Fs%2Fblog_62fda93c01019f1q.html");
            s1 = System.Web.HttpUtility.UrlDecode("http%3A%2F%2Fwww.cnblogs.com%2FYinner%2Farchive%2F2010%2F02%2F27%2F1674667.html");
            //http%3A%2F%2Fwww.fengfly.com%2Fplus%2Fview-211940-2.html
            s1 = System.Web.HttpUtility.UrlDecode("http%3A%2F%2Fwww.fengfly.com%2Fplus%2Fview-211940-2.html");

        }
    }
}
